<template>
  <div>
    <el-row>
      <el-col :span="12">
        <h4>上报案件数</h4>
        <div id="main" style="width: 500px;height: 400px"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px;height: 400px"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "HomeView",
  data() {
    return {

    }
  },
  mounted() { //页面元素渲染之后再触发
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option = {
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        },
      ]
    };
    this.request.get("/echarts/example").then(res => {
      //填空
      option.xAxis.data = res.data.x;
      option.series[0].data = res.data.y
      option.series[1].data = res.data.y
      //数据准备完毕之后再set
      myChart.setOption(option);
    })

    //饼图
    var pieOption = {
      title: {
        text: '法院辅助办案',
        subtext: '办案情况',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '50%',
          data: [
            { value: 1048, name: '总案件数' },
            { value: 735, name: '办理中' },
            { value: 580, name: '已办完' },
            { value: 484, name: '未办理' },
            { value: 300, name: '案件收藏数' }
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);
    pieChart.setOption(pieOption);
  }
}
</script>

<style scoped>

</style>
